<template>
  <div class="home">
    <el-container>
      <el-header>
        <!-- 头部 -->
        <div class="left">
          <img src="../assets/1.png" alt="" class="image" />
          <h2>在线后台管理系统</h2>
        </div>
        <div class="right">
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              {{ Name }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="a">详细信息</el-dropdown-item>
              <el-dropdown-item command="b">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '50px' : '200px'">
          <!-- 侧边栏 -->
          <p class="wz_p" @click="isCollapse = !isCollapse">|||</p>
          <el-menu
            default-active="welcome"
            class="el-menu-vertical-demo"
            background-color="#324057"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            :collapse="isCollapse"
          >
            <el-menu-item index="/welcome">
              <i class="iconfont icon-31shouyexuanzhong"></i>
              <span slot="title">&ensp;首页</span>
            </el-menu-item>

            <el-submenu index="2">
              <template slot="title">
                <i class="iconfont icon-qian"></i>
                <span slot="title">&ensp;资金管理</span>
              </template>
              <el-menu-item index="/index">资金流水</el-menu-item>
            </el-submenu>

            <el-submenu index="1-5">
              <template slot="title">
                <i class="iconfont icon-dakaixinxi"></i>
                <span slot="title">&ensp;信息管理</span>
              </template>
              <el-menu-item index="/info">个人信息</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 坑 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
import { getName } from "../utils/home";
export default {
  // name: 'HomeView',
  // components: {
  //   HelloWorld
  // }
  data() {
    return {
      isCollapse: false,
      Name: "",
    };
  },
  created() {
    getName().then((res) => {
      console.log(res.name);
      this.Name = res.name;
    });
  },
  methods: {
    handleCommand(name) {
      console.log(name);
      if (name == "b") {
        localStorage.removeItem("token");
        this.$router.push("/login");
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.el-header {
  background-color: #324057;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  .left {
    display: flex;
    align-items: center;
    .image {
      width: 45px;
      height: 45px;
      // vertical-align: middle;
      margin-right: 20px;
    }
  }
  .right {
    position: relative;
    // .p_name {
    //   cursor: pointer;
    // }
    .el-dropdown-link {
      cursor: pointer;
      color: #fff;
    }
  }
}

.el-aside {
  background-color: #324057;
  color: #fff;
  height: 100vh;
  .wz_p {
    height: 24px;
    background-color: #283346;
    text-align: center;
  }
}

.el-main {
  background-color: #fff;
}
</style>